package com.wangsh.forward.system.service.impl;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.wangsh.forward.system.pojo.ASysProperty;
import com.wangsh.forward.system.service.ISystemOperService;
import com.wangsh.forward.system.service.ISystemService;
import com.wangsh.webforward.common.pojo.ApiResponse;
import com.wangsh.webforward.common.service.BaseServiceImpl;
import com.wangsh.webforward.common.util.ConstatFinalUtil;

/**
 * 系统模块(非数据库)的Service
 * @author TeaBig
 *
 */
public class SystemOperServiceImpl extends BaseServiceImpl implements ISystemOperService
{
	private ISystemService systemService = new SystemServiceImpl();
	
	@Override
	public ApiResponse<ASysProperty> reloadPropertyService()
	{
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 查询所有的数据 */
		ApiResponse<ASysProperty> apiResponse = this.systemService.findCondListPropertyService(null, condMap);
		List<ASysProperty> sysPropertyList = apiResponse.getDataListJava();
		for (Iterator iterator = sysPropertyList.iterator(); iterator.hasNext();)
		{
			ASysProperty sysProperty = (ASysProperty) iterator.next();
			/* 存储到常量池中 */
			ConstatFinalUtil.SYS_PRO_MAP.put(sysProperty.getName(), sysProperty.toJSON());
		}
		/* 删除temp下面所有的文件 */
		/* tomcat系统的配置 */
		JSONObject pathTomcatJSON = ConstatFinalUtil.SYS_PRO_MAP.get("path.tomcat") ;
		if(pathTomcatJSON != null)
		{
			/* 获取Tomcat的根路径 */
			String pathTomcat = pathTomcatJSON.getString("value") ; 
			/* tomcat临时目录 */
			File batFolder = new File(pathTomcat + "/temp");
			/* 删除目录 */
			this.fileUtil.deleteFile(batFolder,".bat",false);
		}
		return apiResponse ; 
	}
}
